﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;


namespace Library
{
    public partial class NewMagazine : Form
    {
        public List<Magazine> NewMag { get; private set; }

        public NewMagazine()
        {
            InitializeComponent();
            NewMag = new List<Magazine>();

        }

        private void AddMagazine_btn_Click(object sender, EventArgs e)
        {
            string name = TitleMag_txbx.Text.Trim();
            string publisher = PublisherMag_txbx.Text.Trim();
            DateTime publishedDate = PublishedDateMag_dtp.Value;
            string issueNumber = IssueNumberMag_txbx.Text.Trim();
            if (name != string.Empty &&
                publisher != string.Empty &&
                publishedDate != null &&
                issueNumber != string.Empty)
            {
                foreach (Magazine m in NewMag)
                {
                    if (m.Name == name && m.Publisher == publisher && m.PublishedDate == publishedDate && m.IssueNumber == issueNumber)
                    {
                        MessageBox.Show("Такой журнал вы уже добавляли.");
                        return;
                    }
                }
                NewMag.Add(new Magazine (name,publisher,publishedDate,issueNumber));
                countMag_lbl.Text = "Добавлено: " + NewMag.Count;
                return;
            }

            MessageBox.Show("Не все поля заполнены.");
            return;
        }

        private void SaveMagazine_btn_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
